<template>
  <div
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)">
    <!--搜索栏-->
    <common-list-search-bar
      ref="commonListSearchBar"
      :field-arr="searchSittingArray"
      :search-list="searchList">
    </common-list-search-bar>
    <common-list-table
      ref="myCommonListTable"
      :sitting="listTableSitting"
      :search-list="searchList">
      <template slot="actSlot" slot-scope="scope">
        <my-button type="success" :click="function (){detail(scope)}" text="详情" access-action="SupplierOrder/getList"></my-button>
      </template>
    </common-list-table>

    <supplier-order-dialog ref="orderDialog" :success-function="searchList"/>
  </div>
</template>

<script>


import MyButton from '../Common/MyButton'
import SupplierOrderDialog from '../Dialog/SupplierOrderDialog'
export default {
  name: 'OrderPage',
  components: {SupplierOrderDialog, MyButton, },
  watch:{
    '$route':function () {
      this.searchList()
      this.checkMesageParams()
    }
  },
  mounted () {
    // 模拟数据
    // this.$refs.myCommonListTable.setListData(DemoData.Product.list)
    this.checkMesageParams()
    this.searchList()
  },
  data: function () {
    return {
      loading: false,
      // 搜索栏配置项
      searchSittingArray: Object.assign([], this.getFieldArr()),
      listTableSitting: {
        modelName: '供货单列表',
        showSummary:true,
        fieldArr: this.getFieldArr(),
        tableHeight: this.getTableHeight(),
        page: 1,
        pageSize: 20,
        actColumnWidth: 150,
        defaultSort: {
          // prop:'username',
          // order:'descending',
        }
      }
    }
  },
  methods: {
    checkMesageParams:function () {
      if (this.$route.query && this.$route.query.EVENT_PARAMS && this.$route.query.EVENT_PARAMS.length > 0) {
        if (localStorage.getItem('OpenOrderDialog') && localStorage.getItem('OpenOrderDialog') === this.$route.query.EVENT_PARAMS) {
          return;
        }
        this.$refs.orderDialog.hide()
        this.$refs.orderDialog.open(this.$route.query.EVENT_PARAMS)
        this.bus.$emit('OpenOrderMessageCallBus', 'Order_' + this.$route.query.EVENT_PARAMS)
        localStorage.setItem('OpenOrderDialog', this.$route.query.EVENT_PARAMS)
      }
    },
    getFieldArr:function () {
      var arr=DemoData.Order.field;
      let $this=this
      // if (this.$route.query.status && this.$route.query.status.length){
      //   arr.forEach(function (value, index) {
      //     if (value.field==='status'){
      //       arr[index].defaultValue=$this.$route.query.status+''
      //     }
      //   })
      // }
      return arr;
    },
    getTableHeight: function () {
      var height = this.getWinSize().height - 225
      return height > 500 ? height : 500
    },
    // 初始化查询
    searchList: function () {
      // 表格列表,查询参数
      var listTableForm = this.$refs.myCommonListTable.formData

      // 搜索栏,查询参数
      var searchBarForm = this.$refs.commonListSearchBar.getFormData()

      var form = Object.assign({}, listTableForm, searchBarForm)
      // 如果有默认排序 && 默认排序数据未设置,就进行查询请求(默认排序设置会触发查询)
      if (this.listTableSitting.defaultSort && this.listTableSitting.defaultSort.prop && this.$refs.myCommonListTable.formData.sortOrder === '') {
        return ''
      }
      let $this = this
      $this.loading = true
      $this.MyRequest($this.ApiDoNameSupplier + 'SupplierOrder/getList', form, function (data) {
        $this.$refs.myCommonListTable.setListData(data)
        $this.loading = false
        $this.$forceUpdate()
      })
    },
    // 订单详情
    detail: function (infoParams) {
      var info = {}
      if (infoParams && infoParams.rowInfo) {
        info = infoParams.rowInfo
      }
      this.$refs.orderDialog.open(info.id)
    }
  }
}
</script>

<style scoped>

</style>
